package www.wen.com.common.lib.view.popuview

import android.content.Context
import android.view.View
import android.widget.TextView
import androidx.core.view.isVisible
import com.lxj.xpopup.core.CenterPopupView
import com.lxj.xpopup.util.XPopupUtils
import com.xuexiang.xupdate.widget.NumberProgressBar
import www.wen.com.common.R
import www.wen.com.common.lib.extension.setOnClickListenerAgency
import www.wen.com.common.lib.helper.ResultUiCallBack

/**
 * @author WEN
 * @Description:版本升级的弹窗
 * @date 2021/3/3 14:53
 */
class AppUpdatePopupView(
    context: Context,
    private val isForceUpdate: Boolean,
    val content: CharSequence?,
    val strVersion: CharSequence?,
    private val resultCallBack: ResultUiCallBack<String>? = null,
) : CenterPopupView(context), View.OnClickListener {

    lateinit var tvContent: TextView

    lateinit var tvVersion: TextView

    lateinit var tvNotUpDateApp: TextView

    lateinit var tvUpDateApp: TextView

    lateinit var numberProgressBar: NumberProgressBar

    override fun getImplLayoutId(): Int = R.layout.popupview_app_update

    override fun onClick(v: View) {
        resultCallBack?.invoke(v, "", this)
    }

    override fun initPopupContent() {
        super.initPopupContent()
        tvNotUpDateApp = findViewById(R.id.tvNotUpDateApp)
        tvVersion = findViewById(R.id.strVersion)
        tvUpDateApp = findViewById(R.id.tvUpDateApp)
        tvContent = findViewById(R.id.tvContent)
        numberProgressBar = findViewById(R.id.npb_progress)

        tvContent.text = content
        tvVersion.text = strVersion

        numberProgressBar.isVisible = false

        tvNotUpDateApp.isVisible = !isForceUpdate

        setOnClickListenerAgency(this, tvNotUpDateApp, tvUpDateApp)
    }

    override fun getMaxWidth(): Int {
        return (XPopupUtils.getScreenWidth(context) * 0.8f).toInt()
    }

    override fun getPopupHeight(): Int {
        return (XPopupUtils.getScreenHeight(context) * 0.6f).toInt()
    }

}


